import { listCarousel, getCarousel, deleteCarousel } from "@/api/service/carousel/carousel";

import { form, resetForm, showForm } from "./form";
import { keys, query, table } from "./table";

export const list = async () => {
  table.value.loading = true;
  const data = await listCarousel(query.value);
  table.value.data = data.rows;
  query.value.total = data.total;
  table.value.loading = false;
};

export const edit = async (id?: string) => {
  const targetId = id || keys.value[0];
  const data = await getCarousel(targetId);
  form.value = data.data;
  showForm.value = true;
};
export const create = async () => {
  resetForm();
  showForm.value = true;
};
export const del = async (id?: string) => {
  const targetId = [id];
  deleteCarousel(targetId.join(","));
  await list();
  keys.value = [];
};

export const search = () => {
  query.value.pageNum = 1;
  list();
};
